<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="${host_url}/js/app/jquery.min.js"></script>
<script src="/js/app/dropload.min.js"></script>
<script src="${host_url}/js/app/tip_pop.js"></script>
<link rel="stylesheet" href="${host_url}/css/app/common.css">
<link rel="stylesheet" href="/css/app/zengsong.css">
<link rel="stylesheet"  href="${host_url}/css/app/dropload.css">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<title>赠送折扣劵体验</title>

<script type="text/javascript">
$(function(){
	/*  页数 */
	var page_index_all = 2;/*  全部 */
    /* dropload 加载分页 */
    <c:if test="${childList.size()!=0}">
    	loadPagination("listAll",page_index_all,"logAll");
    </c:if> 
});
function loadPagination(div_id, page_index, ul_id){
	$('#'+div_id).dropload({
        scrollArea : window,
        loadDownFn : function(me){
            $.ajax({
                type: 'get',
                url: 'giveDiscountLevelItem?page_index='+page_index,
                dataType: 'text',
                beforeSend: function(request) {
    				request.setRequestHeader("AUTHORIZATION","${token}");
    				request.setRequestHeader("SECRET","${memberId}");
    				request.setRequestHeader("OS","${os}");
    			 }, 
                contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                success: function(msg){
                
                    if($.trim(msg)){
                		page_index++;
                    	$("#"+ul_id).append(msg);
                    	me.resetload();
                   	/*  如果没有数据 */
                    } else{
                        	/*  锁定 */
                        me.lock();
                        	/*  无数据 */
                        me.noData();
                        $("#"+div_id+" .dropload-load").html("已经到底了~");
                    } 
                },
	                error: function(xhr, type){
                    	/*  即使加载出错，也得重置 */
                    me.resetload();
                } 
            });
        }
    });
}
$(function(){
	$("#add_p_m").children().siblings().each(function(){
		$(this).addClass('active');
		$("#level_more").val($(this).next().next().attr('value'));
		return false;
	 }); 
 });
/*(one)选择体验劵*/  
function fn_click_one(id,identity,level){
	var child_member_id=$("#child_member_id").val();
	$("#add_p_o").children().siblings().each(function(){
		if($(this).attr('class')=='active'){
			$("#change_member_id_one").val($(this).attr('id')); 
		} 
		$(this).removeClass('active'); 
			
	});	
	if($("#"+id).attr('class')!='no-active'){
		$("#"+id).addClass('active'); 
		$("#identity").val(identity);
		$("#level_one").val(level);
	}
	
}
/*(more)选择体验劵*/  
function fn_click_more(id,level){
	$("#add_p_m").children().siblings().each(function(){
		if($(this).attr('class')=='active'){
			$("#level_more").val(level);
			$(this).removeClass('active'); 
		} 
	});
	if($("#"+id).attr('class')!='no-active'){
		$("#"+id).addClass('active'); 
		$("#level_more").val(level);
	}
	
}
/*(one)（下一步）赠送体验劵*/  
function fn_give_one(){
	var child_member_id=$("#child_member_id").val();
	$.ajax({
		type:"POST", 	
		url:'updateChildLevel?child_member_id='+child_member_id+'&level='+$("#level_one").val(),	 		

		beforeSend: function(request) {
			request.setRequestHeader("AUTHORIZATION","${token}");
			request.setRequestHeader("SECRET","${memberId}");
			request.setRequestHeader("OS","${os}");
		 }, 
		success: function (data) {
	 		if(data.state=="16003"){
				tip(data.msg,250);
			} 
			if(data.state=="16004"){
				tip(data.msg,250);
			} 
			if(data.state=="16001"){	
				tip(data.msg,250);
				$("#c"+$("#child_member_id").val()).addClass('noshow'); 
				$("#c"+$("#child_member_id").val()).empty(); 
				$("#c"+$("#child_member_id").val()).append('<span>赠送体验券 </span>'); 
				$("#c"+$("#child_member_id").val()).prev().empty(); 
				$("#c"+$("#child_member_id").val()).prev().append('<span style="color:#666;line-height:1.15;"><span style="display:block;padding-bottom:2px;">'+data.result.name+'</span><span  style="display:block;color:#999;font-size:12px;">'+data.result.level_name+'</span></span><span>'+data.result.tel_h+'</span>'); 
			} 
			setTimeout(function(){
				$("#popup_one").hide();
			},1000);
			
		 },	 
		
	}); 
	fn_closePopup();
}
/*（more）批量（下一步）赠送体验劵*/  
function fn_give_more_ios(){
	window.webkit.messageHandlers.ios_open_page.postMessage('WKViewController:::url->${ticketGiveMore_url}?level='+$("#level_more").val()+':::webTitle->赠送折扣体验劵:::isRefresh->YES');
}
function fn_give_more_android(){
	android.startUrl('赠送折扣体验劵','${ticketGiveMore_url}?level='+$("#level_more").val())
}
/* 关闭弹窗 */
function fn_closePopup(type){
	if(type==1){
	$("#popup_one").hide();
	}
	if(type==2){
	$("#popup_more").hide();
	}
}

/*点击赠送体验劵 one */
function fn_change_ticket(id,myLevel_ord){
	$.ajax({
		type:"GET", 	
		url:'checkChildId?id='+id+'&myLevel_ord='+myLevel_ord,	 		

		beforeSend: function(request) {
			request.setRequestHeader("AUTHORIZATION","${token}");
			request.setRequestHeader("SECRET","${memberId}");
			request.setRequestHeader("OS","${os}");
		 }, 
		success: function (data) {
			if(data.state=="16002"){
				tip(data.msg,250);
			} else{
			   $("#add_p_o").empty(); 
			   $("#add_p_o").append(data); 
			   $("#add_p_o").children().siblings().each(function(){
					if(!$(this).attr('class')){
						$(this).addClass('active'); 
						$("#identity").val($(this).next().attr('value'));
						$("#level_one").val($(this).next().next().attr('value'));
						return false;
					}
				});  
				$("#popup_one").show(); 
				$("#child_member_id").val(id); 
			}
		 },	 
	});
} 
/* 点击批量赠送好友体验券 */
function fn_click_give_more(){
	$("#add_p_m").children().siblings().each(function(){
		$(this).removeClass('active');
	 });
	$("#add_p_m").children().siblings().each(function(){
		$(this).addClass('active');
		$("#level_more").val($(this).next().next().attr('value'));
		return false;
	 });
	$("#popup_more").show(); 
}
function fn_citylist_popup_open_ios(){
	window.webkit.messageHandlers.ios_show_country.postMessage('');

}
function setCountry(id, code){
	$("#country_id").val(id);
	$("#default_area_code_ios").empty(); 
	$("#default_area_code_ios").append(code); 
}
function fn_citylist_popup_open(id, code){
	$("#country_id").val(id);
	$("#default_area_code_android").empty(); 
	$("#default_area_code_android").append(code); 
}
function fn_citylist_popup_open_android(){
	 android.setCountryCode();
}
function Page_Restart(){
	android.reLoad();
}
function fn_ios_share(title,content,url,img,type){
	 var shareInfo = JSON.stringify({"title": title, "content": content, "url": url,"share_type": type, "image":img});
	window.webkit.messageHandlers.ios_show_share.postMessage(shareInfo);
}
function fn_regSub() {
	var tel=$("#tel").val();
	var country_id=$("#country_id").val();
	var regSub_url = "checkChildId?tel="+tel+"&country="+country_id+'&myLevel_ord=${myLevel_ord}';
	var reg=/^\d+$/;
	if(!tel){
		tip("请输入手机号",250);
	}
	if(reg.test(tel)){
		$.ajax({
			type:"GET", 	
			url:regSub_url,	
			beforeSend: function(request) {
				request.setRequestHeader("AUTHORIZATION","${token}");
				request.setRequestHeader("SECRET","${memberId}");
				request.setRequestHeader("OS","${os}");
			 },  
			success: function (data) {
				if(data.state=="16002"){
					tip(data.msg,250);
				}else if(data.state=="16004"){
					tip(data.msg,250);
				}else{
					$("#add_p_o").empty(); 
					   $("#add_p_o").append(data); 
					   $("#add_p_o").children().siblings().each(function(){
							if(!$(this).attr('class')){
								$(this).addClass('active'); 
								$("#identity").val($(this).next().attr('value'));
								$("#level_one").val($(this).next().next().attr('value'));
								return false;
							}
						});  
						$("#popup_one").show(); 
						$("#child_member_id").val($("#select_child_id").val()); 
				}  
			 },	 
		});
	}else{
		tip("手机号码格式错误",250);
	}
}
</script>

</head>

<body>
	<input type="hidden" id="country_id" value="1" />
	<input type="hidden" id="child_member_id" value="" />
	<input type="hidden" id="change_member_id_one" value="" />
	<input type="hidden" id="identity" value="" />
	<input type="hidden" id="level_one" value="" />
	<input type="hidden" id="level_more" value="" />
	<div class="main" id="main_sh">
			<div class="content-wrap">
				<img src="${host_url}/img/banner_1.png" alt="" style="width:100%;"">
				<div class="content">
					<p class="btn-frame">
					<c:if test="${'ios'==os}">
						<span id="default_area_code_ios" onclick="fn_citylist_popup_open_ios()">+86</span>
					</c:if>
					<c:if test="${'android'==os}">
					<span id="default_area_code_android" onclick="fn_citylist_popup_open_android()">+86</span>
					</c:if>
					<input type="text" id="tel" value="" placeholder="请输入要赠送好友的手机号码" ></p>
					<button onclick="fn_regSub()">确定</button>
					<p onclick="fn_click_give_more()">批量赠送好友体验券<img src="/img/icon_more.png" alt="" style="width:17px;vertical-align: middle;margin-left:5px;" ></p>
					<h4 class="arrow-title"><span style="display:inline-block;padding:0 15px;background:#fff;">邀请新好友并赠送折扣券</span></h4>
					<p class="flex-layout share">
						<c:if test="${'ios'==os}">
							<span><img src="${host_url}/img/icon_share_1.png" alt="" onclick="fn_ios_share('${shareVO.title}','${shareVO.content}','${shareVO.url}','${shareVO.image}','0')">朋友圈</span>
							<span><img src="${host_url}/img/icon_share_2.png" alt="" onclick="fn_ios_share('${shareVO.title}','${shareVO.content}','${shareVO.url}','${shareVO.image}','1')">微信好友</span>
							<span><img src="${host_url}/img/icon_share_3.png" alt="" onclick="fn_ios_share('${shareVO.title}','${shareVO.content}','${shareVO.url}','${shareVO.image}','2')">复制链接</span>
						</c:if>
						<c:if test="${'android'==os}">
							<span><img src="${host_url}/img/icon_share_1.png" alt="" onclick="android.startShare('${shareVO.title}','${shareVO.content}','${shareVO.url}','${shareVO.image}','1')">朋友圈</span>
							<span><img src="${host_url}/img/icon_share_2.png" alt="" onclick="android.startShare('${shareVO.title}','${shareVO.content}','${shareVO.url}','${shareVO.image}','0')">微信好友</span>
							<span><img src="${host_url}/img/icon_share_3.png" alt="" onclick="android.startShare('${shareVO.title}','${shareVO.content}','${shareVO.url}','${shareVO.image}','2')">复制链接</span>
						</c:if>
						
					</p>
					<h4 class="list-title">可赠送折扣体验券的好友列表</h4>
					<c:if test="${childList.size()!=0}">
						<div class="friend-list" id="listAll">
						 <ul id="logAll">
							<c:forEach items="${childList}" var="c">
							<div class="flex-layout" >
								<p class="leftarea"><img src="${c.logo}" alt=""></p>
								<c:if test="${c.show_state==0}">
									<p class="centerarea"><span>${c.nick_name}</span><span>${c.tel_h}</span></p>
									<p class="rightarea" id="c${c.id}"><span onclick="fn_change_ticket(${c.id},${myLevel_ord})">赠送体验券</span></p>
								</c:if>
								<c:if test="${c.show_state !=0}">
									<p class="centerarea">
										<span style="color:#666;line-height:1.15;">
											<span style="display:block;padding-bottom:2px;">${c.nick_name}</span>
											<c:if test="${c.show_state ==1}">
											<span  style="display:block;color:#999;font-size:12px;">(${c.level_name_str})</span>
											</c:if>
										</span>
										<span>${c.tel_h}</span>
									</p>
									<p class="rightarea noshow" id="c${c.id}"><span>赠送体验券 </span></p>
								</c:if>
							</div>
							</c:forEach>
						  </ul>
						</div>
					</c:if> 
					  <c:if test="${childList.size()==0}">
						<div class="zanwu">
							  <span><img src="/img/app/zanwu.png" style="width:80px;"></span>
							  <p>暂无可赠送的会员</p>
						</div>
					</c:if> 
				</div>
			</div>
	
			<div class="popup-list" style="display:none;" id="popup_one">
				<div id="">
					<h4 >请选择要赠送的体验券类型</h4>
					<div id="add_p_o">
						<c:forEach items="${levelList}" var="c">
						<c:if test="${c.level_ord<=myLevel_ord}">
							<p id="p_${c.level_ord}" onclick="fn_click_one(this.id,'${c.identity}','${c.level}')" value="${c.level_ord}">${c.str_msg}</p>
							<input type="hidden" id="c_identity" value="${c.identity}" />
							<input type="hidden" id="c_level" value="${c.level}" />
						</c:if>	
						<c:if test="${c.level_ord>myLevel_ord}">
							<p class="no-active" value="${c.level_ord}">${c.str_msg}</p>
						</c:if>	
						</c:forEach>
					</div>
						<button onclick="fn_give_one()">下一步</button>
						<p class="close" onclick="fn_closePopup(1)"><img src="${host_url}/img/icon_close.png" alt=""></p>
				</div>
			</div>
			<div class="popup-list" style="display:none;" id="popup_more">
				<div id="">
					<h4 >请选择要赠送的体验券类型</h4>
					<div id="add_p_m">
						<c:forEach items="${levelList}" var="c">
						<c:if test="${c.level_ord*1<=myLevel_ord}">
							<p id="m_${c.level_ord}" onclick="fn_click_more(this.id,'${c.level}')" value="${c.level_ord}">${c.str_msg}</p>
							<input type="hidden" id="c_identity" value="${c.identity}" />
							<input type="hidden" id="c_level" value="${c.level}" />
						</c:if>	
						<c:if test="${c.level_ord*1>myLevel_ord}">
							<p class="no-active" value="${c.level_ord}">${c.str_msg}</p>
						</c:if>	
						</c:forEach>
					</div>
						<c:if test="${'ios'==os}">
							<button onclick="fn_give_more_ios()">下一步</button>
						</c:if>
						<c:if test="${'android'==os}">
						<button onclick="fn_give_more_android()">下一步</button>
						</c:if>
							<p class="close" onclick="fn_closePopup(2)"><img src="${host_url}/img/icon_close.png" alt=""></p>
						
				</div>
			</div>
	</div>

</body>
</html>